<?php
class EventController extends LBController
{
    protected function needAuth()
    {
        return false;
    }
    
    protected function needTimer()
    {
        return false;
    }

    public function addAction()
    {
        $this->assign('title', gettext('add event'));

        if ($this->_request->isPost())
        {
            $userId = $this->getUserId();

            $event = $this->getParam('event', array());
            var_dump($event);

            $who = filter_var($event['who']);
            $eventTime = filter_var($event['eventTime']);
            $location = filter_var($event['location'], FILTER_VALIDATE_INT);
            $city = filter_var($event['city'], FILTER_VALIDATE_INT);
            $description = filter_var($event['description']);
            $link = filter_var($event['link'], FILTER_VALIDATE_URL);

            //$fileInfo = FileUploader::getFileInfo('poster', $userId);

            $ev = new Event();
            $ev->createMusicEvent($userId, $who, $eventTime, $location, $city, $description, $link);
            $ev->save();

            $res = array();
            $res['msg'] = gettext('add succ!');
            $res['errno'] = self::AJAX_RESPONSE_SUCC;
            $this->renderAjax($res);
        }
        else
        {
            $this->assign('skipSiderBar', true);
            $this->render();
        }
    }

    public function listAction()
    {/*{{{*/
        $ev = new Event();
        $from = '2001-01-01';
        $to = '2009-01-01';
        $res = $ev->find($from, $to);
        $mine = $ev->findByAttender($this->getUserId());

        $this->assign('title', gettext('events list'));
        $this->assign('from', $from);
        $this->assign('to', $to);
        $this->assign('res', $res);
        $this->assign('mine', $mine);
        $this->assign('skipSiderBar', true);
    }/*}}}*/

    public function detailAction(){}

    public function attendAction()
    {
        $event = filter_var($this->getParam('event'), FILTER_VALIDATE_INT);
        $userId = $this->getUserId();
        $er = new EventRef();
        $er->add($userId, $event);
        $res['errno'] = self::AJAX_RESPONSE_SUCC;
        $res['msg'] = 'succ';
        $this->renderAjax($res);
    }

    public function quitAction()
    {
        $event = filter_var($this->getParam('event'), FILTER_VALIDATE_INT);
        $userId = $this->getUserId();
        $er = new EventRef();
        $er->del($userId, $event);
        $res['errno'] = self::AJAX_RESPONSE_SUCC;
        $res['msg'] = 'succ';
        $this->renderAjax($res);

    }
}
